<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use OT\DataDictionary;

/**
 * 前台首页控制器
 * 信息
 */
class InfoController extends HomeController {

	//系统首页
    public function index(){
        $this->assign("title","企业简介");
        $this->assign('introduce',$this->get_content('introduce')); // 获取介绍
        $this->display();
    }


    function flash(){
        $this->assign("title","企业视频");
        $where = array();
        if(I('get.video_id')) $where['id'] = intval(I('get.video_id'));
        $video = M('video')->where($where)->order('id desc')->find();
        $video['play_num'] > 10000 && $video['play_num'] = number_format($video['play_num'] / 10000, 1) . '万'; // 如果播放次数大于10000次转换为xxx.x万的格式
        $video_list = M('video')->order('id desc')->field(true)->select();
        $this->assign('video', $video);
        $this->assign('video_list', $video_list);
        $this->display();
    }

    function culture(){
        $this->assign("title","企业文化");
        $this->assign('culture',$this->get_content('culture')); // 获取文化内容
        $this->display();
    }

    function recruit(){
        $tel = M("config")->where(array("name"=>array("eq","TEL")))->getField("value");
        $this->assign("tel",$tel);
        $this->assign("title","企业招聘");
        $job_list = M('job')->order('id desc')->field(true)->select();
        $this->assign('job_list', $job_list);
        $this->display();
    }

    private function get_content($type){
        $this->assign("title","企业简介");
        $info = M('about')->where(array('type'=>$type))->find();
        $info['pic'] = _parse_pics($info['pic']);
        return $info;
    }

    public function feedback(){
        if(IS_POST){
            $phone = I("phone",'','strip_tags');
            $content = I("content",'',"htmlspecialchars");
            $status =0;
            $msg ="";
            if(!preg_grep('/^1[3|4|5|8]\d{9}$/', array($phone))){
                $msg ="请输入正确的电话号码";
            }else{
                $arr = array(
                    "phone"=>$phone,
                    "content"=>$content,
                    "add_time"=>time()
                );
                $result = M("feedback")->add($arr);
                if($result){
                    $status =1;
                    $msg ="感谢您的宝贵意见！";
                }
            }
            echo json_encode(array("status"=>$status,"msg"=>$msg));

        }else{
            $this->assign("title","意见反馈");
            $this->display();
        }
    }

    public function disclaimer(){
        $this->assign("title","免责声明");
        $info = M("Info")->where(array("title"=>array("eq","免责声明")))->find();
        $this->assign("info",$info);
        $this->display();
    }


}